import { cloudService } from './index'
import type { IFoodQuery, IRecipe, IRecord, IStats } from '@/types/food'
import type { IStatsChart } from 'vue3-common/types'

export const addRecipeApi = (recipe: IRecipe): Promise<boolean> =>
  cloudService({
    url: '/food-api/food/recipe',
    method: 'post',
    data: recipe
  })

export const updateRecipeApi = (id: number, recipe: IRecipe): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/recipe/${id}`,
    method: 'put',
    data: recipe
  })

export const deleteRecipeApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/recipe/${id}`,
    method: 'DELETE'
  })

export const queryRecipeByIdApi = (id: number): Promise<IRecipe> =>
  cloudService({
    url: `/food-api/food/recipe/${id}`,
    method: 'get'
  })

export const queryRecipeByUserApi = (id: number): Promise<IRecipe[]> =>
  cloudService({
    url: `/food-api/food/recipe/user/${id}`,
    method: 'get'
  })

export const queryRecipeUserFavouriteApi = (): Promise<IRecipe[]> =>
  cloudService({
    url: '/food-api/food/recipe/user/favourite',
    method: 'get'
  })

export const queryRecipeApi = (query: IFoodQuery): Promise<IRecipe[]> =>
  cloudService({
    url: '/food-api/food/recipe',
    method: 'get',
    params: { ...query }
  })

export const queryRecipeByPageApi = (currentPage: number, pageSize: number,
  query: IFoodQuery): Promise<any> =>
  cloudService({
    url: '/food-api/food/recipe/page',
    method: 'get',
    params: { currentPage, pageSize, ...query }
  })

export const queryFoodNameListApi = (): Promise<string[]> =>
  cloudService({
    url: '/food-api/food/recipe/name',
    method: 'get'
  })

export const addRecordApi = (record: IRecord): Promise<boolean> =>
  cloudService({
    url: '/food-api/food/record',
    method: 'post',
    data: record
  })

export const updateRecordApi = (id: number, record: IRecord): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/record/${id}`,
    method: 'put',
    data: record
  })

export const deleteRecordApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/record/${id}`,
    method: 'DELETE'
  })

export const addRecipeCommentApi = (id: number, content: string): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/recipe/${id}/comment`,
    method: 'post',
    params: { content }
  })

export const addRecipeLikeApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/recipe/${id}/like`,
    method: 'post'
  })

export const deleteRecipeLikeApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/recipe/${id}/like`,
    method: 'delete'
  })

export const addRecipeFavouriteApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/recipe/${id}/favourite`,
    method: 'post'
  })

export const deleteRecipeFavouriteApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/food-api/food/recipe/${id}/favourite`,
    method: 'delete'
  })

export const queryRecordApi = (startDate: string, endDate: string): Promise<IRecord[]> =>
  cloudService({
    url: '/food-api/food/record',
    method: 'get',
    params: { startDate, endDate }
  })

export const queryCategoryApi = (): Promise<string[]> =>
  cloudService({
    url: '/food-api/food/category',
    method: 'get'
  })

export const queryStatsApi = (): Promise<IStats> =>
  cloudService({
    url: '/food-api/food/stats',
    method: 'get'
  })

export const queryRecordStatsApi = (): Promise<IStatsChart[]> =>
  cloudService({
    url: '/food-api/food/stats/record',
    method: 'get'
  })

export const queryCategoryStatsApi = (): Promise<IStatsChart[]> =>
  cloudService({
    url: '/food-api/food/stats/category',
    method: 'get'
  })

export const queryRankStatsApi = (): Promise<IStatsChart[]> =>
  cloudService({
    url: '/food-api/food/stats/rank',
    method: 'get'
  })
